package server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

public class MyServerBootStrap {

    public static void main(String[] args) throws InterruptedException {
        final EventLoopGroup bossGroup = new NioEventLoopGroup();
        final EventLoopGroup workerGroup = new NioEventLoopGroup();
        new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(
                new ChannelInitializer<SocketChannel>() {
                    protected void initChannel(SocketChannel ch) throws Exception {
                        //如果超过设置的时间就响应userEcentTriggered
                        //第一个参数,客户端未向服务端发送消息的时间
                        //第二个参数,服务端未向客户端发送消息的时间
                        //第三个参数,两边都未发送的时间
                        //0代表不响应
                        ch.pipeline().addFirst("idleHandler", new IdleStateHandler(0, 0, 20));
                        ch.pipeline().addLast("myHander", new MyServerHander());
                    }
                }
        ).bind( 8888).sync();

    }

}
